<template>
  <div id="app">
    <!-- 路由出口 -->
    <router-view/>

    <!--
        -- 底部导航 --
      route:开启路由模式
      active-color: 选中颜色
      inactive-color:初始颜色
      $route.meta.showTabBar:当路由元中标记showTabBar为true才让tabbar显示
    -->
    <van-tabbar
        class="tabbar"
        route
        active-color="#6fbcef"
        inactive-color="#b4b4bd"
        v-show="$route.meta.showTabBar"
    >
      <van-tabbar-item
          v-for="(item, index) in routerOptions"
          :key="index"
          :to="item.path"
      >
        <span>{{ item.meta.title }} </span>
        <template #icon>
          <i class="iconfont" :class="item.meta.icon"></i>
        </template>
      </van-tabbar-item>


    </van-tabbar>
  </div>


</template>

<script>
export default {
  name: 'app',
  computed: {
    // 利用计算属性,截取路由中3个需显示的tabbar
    routerOptions() {
      return this.$router.options.routes.slice(1, 5)
    }
  },
  created() {
    console.log(this.$router)
  }

}
</script>
<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
